package com.hdsx.netty.bio;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author 占贤银
 * time 2024/7/30 0:17
 * description 生命之灯因热情而点燃，生命之舟因拼搏而前行
 */
public class BioServer {

    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket();
            serverSocket.bind(new InetSocketAddress(8080));
            // 不断轮询
                // 阻塞等待客户端连接
            Socket socket = serverSocket.accept();
            System.out.println("等待客户端连接：" + socket.getLocalAddress().getHostAddress() + ":" + socket.getLocalPort());
            InputStream inputStream = socket.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String msg = "";
            if ((msg = bufferedReader.readLine()) != null) {
                System.out.println(msg);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
